//
// Created by Administrator on 2021/11/9.
// May Saint Diana bless you!
//
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

class Solution {
public:
    vector<int> deckRevealedIncreasing(vector<int> &deck) {
        sort(deck.begin(), deck.end());
        vector<int>ans(deck.size(),0);
        queue<int>q; // 用队列来模拟牌的抽取规则 存储原始数组中的下标  依次出队的顺序就是原始数组中各个位置被抽取的顺序 按照这个顺序把牌从小到大放好就行
        for (int i = 0; i < deck.size(); ++i) {
            q.push(i);
        }
        int cur = 0;
        while (!q.empty()){
            int index = q.front();
            ans[index] = deck[cur++];
            q.pop();
            q.push(q.front()); // 下一个放到队尾
            q.pop();
        }
        return ans;

    }
};

int main() {
    vector<int> deck{17, 13, 11, 2, 3, 5, 7};
    Solution solution;
    auto ans = solution.deckRevealedIncreasing(deck);
    for (const auto &x: ans)cout << x << endl;
    return 0;
}
